package event;

import influence.Influence;

import java.util.ArrayList;
import java.util.List;

import processing.core.PApplet;
import processing.core.PImage;
import processing.core.PVector;
import run.Doodler;
import run.Env;
import run.LineCell;
import action.Action;

public class PaintTowardsNearbyCellsEvent implements Event {

	private final List<LineCell> nearbyCells;

	public PaintTowardsNearbyCellsEvent(List<LineCell> nearbyCells) {
		this.nearbyCells = nearbyCells;
	}

	public List<Influence> getOutputInfluences() {
		ArrayList<Influence> list = new ArrayList<Influence>();
		
		PApplet p = Doodler.instance;
		
		// TODO only sometimes... (shoudl be usef in Scale)
		if (p.random(1F) < 0.2)
		list.add(new Influence() {

			public Action getAction() {
				return new Action() {
					boolean active = true;
					
					public void doAction(LineCell lineCell, Float scale) {
						PVector loc = lineCell.loc;
						PApplet p = Doodler.instance;
						LineCell nearest = Env.nearest(lineCell, nearbyCells);

						if (loc.dist(nearest.loc) < 30) {
							// TODO do a color compromise or gradient oooo. between this and
							// the other dudes
							p.stroke(lineCell.r, lineCell.g, lineCell.b, 1);
							p.line(loc.x, loc.y, nearest.loc.x, nearest.loc.y);
							
						}
						else
							active = false;
						
					}
					public boolean isActive() {
						return active;
					}
					
				};
			}

			public float getScale() {
				return 0;
			}
			
		});
		
		return list;
	}

}
